import React, { Component } from "react";
import Comment from "./Comment";
import PropTypes from "prop-types";

class CommentList extends Component {
  handleDeleteComment = index => {
    let { onDeleteComment } = this.props;
    if (onDeleteComment) {
      onDeleteComment(index);
    }
  };
  render() {
    return (
      <div>
        {this.props.comments.map((v, i) => (
          <Comment
            comment={v}
            key={i}
            index={i}
            onDeleteComment={this.handleDeleteComment}
          />
        ))}
      </div>
    );
  }
}
CommentList.defaultProps = {
  comments: []
};
CommentList.propTypes = {
  comments: PropTypes.array,
  onDeleteComment: PropTypes.func
};

export default CommentList;
